package com.bdqn.mr.fullsort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class FlowMapper extends Mapper<LongWritable, Text, FlowBean, Text> {

    // key
    private FlowBean flowBean = new FlowBean();
    // value
    private Text phone = new Text();

    // 13470253144	180	180	360


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] fields = line.split("\t");

        // 手机号
        phone.set(fields[0]);

        // 流量对象
        flowBean.setUpFlow(Long.parseLong(fields[1]));
        flowBean.setDownFlow(Long.parseLong(fields[2]));
        flowBean.setTotalFlow();

        context.write(flowBean,phone);
    }
}
